package domain

import "net/http"

type User struct {
	ID            string   `json:"id" gorm:"primaryKey"`
	Name          string   `json:"name" validate:"required,match"`
	Password      string   `json:"password" validate:"required,match"`
	Email         string   `json:"email" validate:"email"`
	SettingsRefer int      `json:"settings_refer" gorm:"autoIncrement"`
	Settings      Settings `json:"settings" gorm:"foreignKey:SettingsRefer"`
	Created       int64    `json:"create_at" gorm:"autoCreateTime"`
	Updated       int64    `json:"update_at" gorm:"autoUpdateTime"`
}

type ResiterUser struct {
	Name       string `json:"name" validate:"match"`
	Email      string `json:"email" validate:"email"`
	Password   string `json:"password" validate:"match"`
	RePassword string `json:"re_password"`
}

type LoginUser struct {
	Account  string `json:"account" validate:"match|email"`
	Password string `json:"password" validate:"match"`
}

type Settings struct {
	ID            string `json:"id" gorm:"primaryKey"`
	NickName      string `json:"nick_name" validate:"lte=32"`
	Introducation string `json:"introducation" validate:"lte=100"`
	PersonalWeb   string `json:"personal_web" validate:"lte=32"`
}

type Reseting struct {
	Email        string `json:"email"`
	Captcha      string `json:"captcha"`
	New_Password string `json:"new_password"`
	RePassword   string `json:"re_password"`
}

type UserHandler interface {
	// login & logout
	Login(w http.ResponseWriter, r *http.Request)
	Logout(w http.ResponseWriter, r *http.Request)

	// register user
	Register(w http.ResponseWriter, r *http.Request)

	// update settings
	GetSettings(w http.ResponseWriter, r *http.Request)
	UpdateSettings(w http.ResponseWriter, r *http.Request)

	// reset password
	SendCaptcha(w http.ResponseWriter, r *http.Request)
	ResetPassword(w http.ResponseWriter, r *http.Request)
}

type UserService interface {
	// register
	CheckUser(regUser *ResiterUser) error
	CreateUser(regUser *ResiterUser) error

	// Login
	AuthenticateUser(loginUser *LoginUser) (*User, error)

	// settings
	GetUserByID(userID string) (*User, error)
	UpdateUser(user *User) error

	// reset password
	Send(email string) error
	GetUserByEmail(email string) (*User, error)
	ResetPassword(reseting *Reseting) error
}

type UserRepository interface {
	CreateUser(user *User) error
	UpdateUser(user *User) error
	GetUserByID(userID string) (*User, error)
	GetUserByName(name string) (*User, error)
	GetUserByEmail(email string) (*User, error)
}
